package nl.project.data;

import nl.project.data.controller.MembersDAO;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

public class Student extends User {
	private int studentId;
	private String classCode; // H4a etc.
	private Key key;
	private int parentId;

	public Student(int studentId) throws EntityNotFoundException {
		this.studentId = studentId;
		// fill all the fields with the right info
		getStudentInfo();
	}

	public Student(String studentId) throws EntityNotFoundException {
		this(Integer.parseInt(studentId));
	}

	/**
	 * This will acquire all the info from the database
	 */
	public void getStudentInfo() throws EntityNotFoundException {
		Key k = KeyFactory.createKey("Students", "Students");
		Entity student = MembersDAO.getEntityInfo(this.studentId, k, "studentId", "Student");
		key = student.getKey();
		
		this.firstName   = (String)  student.getProperty("firstName");
		this.surName     = (String)  student.getProperty("surName");
		this.preposition = (String)  student.getProperty("preposition");
		this.classCode   = (String)  student.getProperty("classCode");
		this.parentId    = Integer.parseInt((String) student.getProperty("parentId"));
//		this.lattitude   = (String)  student.getProperty("lattitude");
//		this.longitude   = (String)  student.getProperty("longitude");
	}

	public int getStudentId() {
		return this.studentId;
	}

	@Override
	public String toString() {
		return "Student with id: " + this.studentId;
	}

	public Key getKey() {
		return key;
	}

	public String getClassCode() {
		return classCode;
	}


	public int getStudentParentId() {
		return parentId;
	}

}
